//
//  HosDepartmentCell.m
//  Doctor1.0
//
//  Created by mk on 15/11/19.
//  Copyright (c) 2015年 cocoa-mk. All rights reserved.
//

#import "HosDepartmentCell.h"

@implementation HosDepartmentCell

- (void)awakeFromNib {
    // Initialization code
}


-(void)fillMrkaDataWith:(NSMutableArray *)arrayData title:(NSString *)strTit
{
    
    labTitle.text = strTit;
    if ([strTit isEqualToString:@"口腔科"])
    {
      [imageIcon setImage:[UIImage imageNamed:[NSString stringWithFormat:@"hos_kouqiang_marks_icon.png"]]];
    }
   else if ([strTit isEqualToString:@"妇产科"])
    {
        [imageIcon setImage:[UIImage imageNamed:[NSString stringWithFormat:@"hos_fuchan_marks_icon.png"]]];
    }
   else if ([strTit isEqualToString:@"眼科"])
    {
        [imageIcon setImage:[UIImage imageNamed:[NSString stringWithFormat:@"hos_yanke_marks_icon.png"]]];
    }
   else if ([strTit isEqualToString:@"骨科"])
    {
        [imageIcon setImage:[UIImage imageNamed:[NSString stringWithFormat:@"hos_guke_marks_icon.png"]]];
    }
   else if ([strTit isEqualToString:@"其他"])
    {
        [imageIcon setImage:[UIImage imageNamed:[NSString stringWithFormat:@"hos_qita_marks_icon.png"]]];
    }
   else if ([strTit isEqualToString:@"外科"])
    {
        [imageIcon setImage:[UIImage imageNamed:[NSString stringWithFormat:@"hos_waike_marks_icon.png"]]];
    }
   else if ([strTit isEqualToString:@"小儿外科"])
    {
        [imageIcon setImage:[UIImage imageNamed:[NSString stringWithFormat:@"hos_xiaoer_marks_icon.png"]]];
    }
    
    
    int Y = 0;
    int X = 10;
    int viewW = appScreenWidth-20;
    for (int i = 0; i<arrayData.count; i++)
    {
        NSString * strTitle = [[arrayData objectAtIndex:i] objectForKey:@"name"];
        
        CGSize sizeMax = [strTitle boundingRectWithSize:CGSizeMake(viewW,17) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
    
        if ((X+sizeMax.width+15) > viewW)
        {
            X = 10;
            Y = (Y + 40);
        }
        
        UIButton * btnMrk = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnMrk setTitle:strTitle forState:UIControlStateNormal];
        btnMrk.titleLabel.font = [UIFont systemFontOfSize:14];
        [btnMrk setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btnMrk.layer.cornerRadius = 8;
        btnMrk.clipsToBounds = YES;
        [btnMrk setBackgroundColor:UIColorFromRGB(0xf2, 0xf2, 0xf2)];
        btnMrk.tag = i;
        [btnMrk addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];
        
        btnMrk.frame = CGRectMake(X, Y,(sizeMax.width+10),35);
        [viewMarks addSubview:btnMrk];
        
        X = (X+sizeMax.width+15);
    }
    
    //NSLog(@"==%d",Y);

    for (NSLayoutConstraint *constraints in [viewMarks constraints])
    {
        if (constraints.firstItem == viewMarks && constraints.firstAttribute == NSLayoutAttributeHeight)
        {
            constraints.constant = (Y+35+10);//35是最后一行标签的高度
            break;
        }
    }

    
}


-(void)btnclick:(id)sender
{
    UIButton * btn = (UIButton *)sender;
    
    if ([self.delegate respondsToSelector:@selector(clickMarkeWith:selectIndex:)])
    {
        [self.delegate clickMarkeWith:self selectIndex:btn.tag];
    }

}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
